/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sadhar.sipp.perekamanjeniskegiatanpopup;

import org.sadhar.sia.framework.ClassApplicationModule;
import org.sadhar.sipp.perekamanjeniskegiatan.PerekamanJenisKegiatan;
import org.sadhar.sipp.perekamanjeniskegiatan.PerekamanJenisKegiatanDAO;
import org.sadhar.sipp.perekamanjeniskegiatan.PerekamanJenisKegiatanDAOImpl;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

/**
 *
 * @author hendro
 */
public class JenisKegiatanPopupWnd extends ClassApplicationModule {

    private Listbox lstboxJenisKegiatan;
    private Textbox txtboxKeySearch;
    private PerekamanJenisKegiatanDAO jenisKegiatanDAO;

    public JenisKegiatanPopupWnd() {
        this.jenisKegiatanDAO = new PerekamanJenisKegiatanDAOImpl();
    }

    public void onCreate() throws Exception {
        lstboxJenisKegiatan = (Listbox) getFellow("lstboxJenisKegiatan");
        txtboxKeySearch = (Textbox) getFellow("txtboxKeySearch");
        load();
    }

    public void load() throws Exception {
        int no = 1;
        lstboxJenisKegiatan.getItems().clear();
        for (PerekamanJenisKegiatan jenis : jenisKegiatanDAO.list(txtboxKeySearch.getValue())) {
            Listitem item = new Listitem();
            item.setValue(jenis);
            item.appendChild(new Listcell(String.valueOf(no++)));
            item.appendChild(new Listcell(jenis.getJenisKegiatan()));
            lstboxJenisKegiatan.appendChild(item);
        }
    }

    public void lstboxJenisKegiatanOnSelect() throws Exception {
        Window window = (Window) this.getRoot().getFellow("contentDiv").getFirstChild();
        Textbox txtboxJenisKegiatan = (Textbox) window.getFellow("txtboxJenisKegiatan");
        Textbox txtboxKodeJenisKegiatan = (Textbox) window.getFellow("txtboxKodeJenisKegiatan");
        PerekamanJenisKegiatan jenis = (PerekamanJenisKegiatan) lstboxJenisKegiatan.getSelectedItem().getValue();
        txtboxKodeJenisKegiatan.setValue(jenis.getKodeJenisKegiatan() + "");
        txtboxJenisKegiatan.setValue(jenis.getJenisKegiatan());
        this.detach();
    }
}
